﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataRow Convert2KSLEIST(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryKSLEIST(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                default:
                    #region====YGR======
                    dwReturn["KSLMANDANT"] = "00";
                    dwReturn["KSLAUFKRS"] = "  ";
                    dwReturn["KSLAUFLFD"] = "000000";
                    dwReturn["KSLAUFPOS"] = "000";
                    dwReturn["KSLAFOLGE"] = "000";
                    dwReturn["KSLAENDZL"] = "0";
                    dwReturn["KSLMDAT"] = "0";
                    dwReturn["KSLSCHICHT"] = "0";
                    dwReturn["KSLMZTV"] = "0";
                    dwReturn["KSLMZTB"] = "0";
                    dwReturn["KSLPERSNR"] = "        ";
                    dwReturn["KSLMBENID"] = "        ";
                    dwReturn["KSLMPROG"] = "        ";
                    dwReturn["KSLMAFOLGE"] = "000";
                    dwReturn["KSLMCODE"] = "   ";
                    dwReturn["KSLSA"] = "1";
                    dwReturn["KSLHERK"] = "P";
                    dwReturn["KSLVST"] = "N";
                    dwReturn["KSLIKOSTBW"] = " ";
                    dwReturn["KSLKAP"] = " ";
                    dwReturn["KSLDIV"] = " ";
                    dwReturn["KSLVERT"] = "N";
                    dwReturn["KSLMELDKZ"] = "1";
                    dwReturn["KSLERST"] = "J";
                    dwReturn["KSLAUFTYP"] = "V";
                    dwReturn["KSLAUFART"] = "GP";
                    dwReturn["KSLTP"] = "0000";
                    dwReturn["KSLFOLGEV"] = "00";
                    dwReturn["KSLFOLGEB"] = "00";
                    dwReturn["KSLSTKNR"] = "            ";
                    dwReturn["KSLAGANG"] = "               ";
                    dwReturn["KSLPLANKZ"] = " ";
                    dwReturn["KSLFIX"] = "N";
                    dwReturn["KSLMANUELKZ"] = "J";
                    dwReturn["KSLANTERLS"] = "0";
                    dwReturn["KSLERSTKZ"] = " ";
                    dwReturn["KSLZTAMMELD"] = " ";
                    dwReturn["KSLKUNDNR"] = "00000000";
                    dwReturn["KSLWERK"] = "   ";
                    dwReturn["KSLABT"] = "   ";
                    dwReturn["KSLWAKZ"] = "G";
                    dwReturn["KSLART"] = "30001               ";
                    dwReturn["KSLVAR"] = "   ";
                    dwReturn["KSLDESS"] = "          ";
                    dwReturn["KSLCOLORIT"] = "          ";
                    dwReturn["KSLBESCHICH"] = "          ";
                    dwReturn["KSLFARBE"] = "YB005     ";
                    dwReturn["KSLZUSTAND"] = "    ";
                    dwReturn["KSLPROGRP"] = "   ";
                    dwReturn["KSLARTGRP"] = "   ";
                    dwReturn["KSLKAAGRA"] = "     ";
                    dwReturn["KSLKAAGRP"] = "  ";
                    dwReturn["KSLKZINLEXP"] = " ";
                    dwReturn["KSLKPFL"] = " ";
                    dwReturn["KSLME"] = "5";
                    dwReturn["KSLMGANZ"] = "0";
                    dwReturn["KSLMGMTR"] = "0";
                    dwReturn["KSLMGQM"] = "0";
                    dwReturn["KSLMGKG"] = "0";
                    dwReturn["KSLSAKSTKRS"] = "  ";
                    dwReturn["KSLSAKST"] = "0000";
                    dwReturn["KSLSMNRKRS"] = "  ";
                    dwReturn["KSLSMLFDNR"] = "0000";
                    dwReturn["KSLSMPOS"] = "00";
                    dwReturn["KSLSEVARHNR"] = "  ";
                    dwReturn["KSLSEVARUNR"] = "  ";
                    dwReturn["KSLSMZT"] = "0";
                    dwReturn["KSLSPZT"] = "0";
                    dwReturn["KSLSRML"] = "0";
                    dwReturn["KSLSRMS"] = "0";
                    dwReturn["KSLSRPZ"] = "0";
                    dwReturn["KSLGKSTKRS"] = "  ";
                    dwReturn["KSLGKST"] = "0000";
                    dwReturn["KSLIAKSTKRS"] = "  ";
                    dwReturn["KSLIAKST"] = "0000";
                    dwReturn["KSLIMNRKRS"] = "  ";
                    dwReturn["KSLIMLFDNR"] = "0000";
                    dwReturn["KSLIMPOS"] = "00";
                    dwReturn["KSLIEVARHNR"] = "  ";
                    dwReturn["KSLIEVARUNR"] = "  ";
                    dwReturn["KSLIMZT"] = "0";
                    dwReturn["KSLIPZT"] = "0";
                    dwReturn["KSLIRML"] = "0";
                    dwReturn["KSLIRMS"] = "0";
                    dwReturn["KSLIRPZ"] = "0";
                    dwReturn["KSLLIEFNR"] = "        ";
                    dwReturn["KSLRENR"] = "          ";
                    dwReturn["KSLREPOS"] = "000";
                    dwReturn["KSLLSKOST"] = "0";
                    dwReturn["KSLLIKOST"] = "0";
                    dwReturn["KSLLIKOSTI"] = "0";
                    dwReturn["KSLRSKOST"] = "0";
                    dwReturn["KSLRIKOST"] = "0";
                    dwReturn["KSLRIKOSTI"] = "0";
                    dwReturn["KSLRSKOSTF"] = "0";
                    dwReturn["KSLRIKOSTF"] = "0";
                    dwReturn["KSLRIKOSTIF"] = "0";
                    dwReturn["KSLSQKOSTM1"] = "0";
                    dwReturn["KSLSQKOSTM2"] = "0";
                    dwReturn["KSLSQKOSTM3"] = "0";
                    dwReturn["KSLSQKOSTM4"] = "0";
                    dwReturn["KSLSQKOSTM5"] = "0";
                    dwReturn["KSLIQKOSTM1"] = "0";
                    dwReturn["KSLIQKOSTM2"] = "0";
                    dwReturn["KSLIQKOSTM3"] = "0";
                    dwReturn["KSLIQKOSTM4"] = "0";
                    dwReturn["KSLIQKOSTM5"] = "0";
                    dwReturn["KSLIQKOSTIM1"] = "0";
                    dwReturn["KSLIQKOSTIM2"] = "0";
                    dwReturn["KSLIQKOSTIM3"] = "0";
                    dwReturn["KSLIQKOSTIM4"] = "0";
                    dwReturn["KSLIQKOSTIM5"] = "0";
                    dwReturn["KSLSQKOSTP1"] = "0";
                    dwReturn["KSLSQKOSTP2"] = "0";
                    dwReturn["KSLSQKOSTP3"] = "0";
                    dwReturn["KSLSQKOSTP4"] = "0";
                    dwReturn["KSLSQKOSTP5"] = "0";
                    dwReturn["KSLIQKOSTP1"] = "0";
                    dwReturn["KSLIQKOSTP2"] = "0";
                    dwReturn["KSLIQKOSTP3"] = "0";
                    dwReturn["KSLIQKOSTP4"] = "0";
                    dwReturn["KSLIQKOSTP5"] = "0";
                    dwReturn["KSLIQKOSTIP1"] = "0";
                    dwReturn["KSLIQKOSTIP2"] = "0";
                    dwReturn["KSLIQKOSTIP3"] = "0";
                    dwReturn["KSLIQKOSTIP4"] = "0";
                    dwReturn["KSLIQKOSTIP5"] = "0";
                    dwReturn["KSLGSKOST1"] = "0";
                    dwReturn["KSLGSKOST2"] = "0";
                    dwReturn["KSLGSKOST3"] = "0";
                    dwReturn["KSLGSKOST4"] = "0";
                    dwReturn["KSLGSKOST5"] = "0";
                    dwReturn["KSLGIKOST1"] = "0";
                    dwReturn["KSLGIKOST2"] = "0";
                    dwReturn["KSLGIKOST3"] = "0";
                    dwReturn["KSLGIKOST4"] = "0";
                    dwReturn["KSLGIKOST5"] = "0";
                    dwReturn["KSLGIKOSTI1"] = "0";
                    dwReturn["KSLGIKOSTI2"] = "0";
                    dwReturn["KSLGIKOSTI3"] = "0";
                    dwReturn["KSLGIKOSTI4"] = "0";
                    dwReturn["KSLGIKOSTI5"] = "0";
                    dwReturn["KSLAENDZLST"] = "0";
                    dwReturn["KSLAENDZLSV"] = "0";
                    dwReturn["KSLENDKZ"] = " ";
                    dwReturn["KSLABG"] = " ";
                    dwReturn["KSLARBPL"] = "        ";
                    dwReturn["KSLLSTAR"] = "      ";
                    dwReturn["KSLLO"] = "  ";
                    dwReturn["KSLPAUFKRS"] = "  ";
                    dwReturn["KSLPAUFLFD"] = "000000";
                    dwReturn["KSLPAFOLGE"] = "000";
                    dwReturn["KSLFILLER"] = "0000000000000      *                                   ";
                    #endregion
                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapKSLEIST(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void DeleteKSLEIST(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM KSLEIST WHERE"
                          + "  KSLMANDANT=:KSLMANDANT AND KSLAUFKRS=:KSLAUFKRS AND KSLAUFLFD=:KSLAUFLFD AND KSLAUFPOS=:KSLAUFPOS AND KSLAFOLGE=:KSLAFOLGE";
                    or1.Parameters.Add("KSLMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("KSLAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("KSLAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    or1.Parameters.Add("KSLAUFPOS", OracleType.NVarChar).Value = dwData["ABFAUFPOS"].ToString();
                    or1.Parameters.Add("KSLAFOLGE", OracleType.NVarChar).Value = dwData["ABFAFOLGE"].ToString();
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM KSLEIST WHERE"
                          + "  KSLMANDANT=:KSLMANDANT AND KSLAUFKRS=:KSLAUFKRS AND KSLAUFLFD=:KSLAUFLFD AND KSLAUFPOS=:KSLAUFPOS AND KSLAFOLGE=:KSLAFOLGE AND KSLAENDZL = :KSLAENDZL ";
                    or1.Parameters.Add("KSLMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("KSLAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("KSLAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    or1.Parameters.Add("KSLAUFPOS", OracleType.NVarChar).Value = dwData["ABFAUFPOS"].ToString();
                    or1.Parameters.Add("KSLAFOLGE", OracleType.NVarChar).Value = dwData["ABFAFOLGE"].ToString();
                    or1.Parameters.Add("KSLAENDZL", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    break;
                default:
                    break;
            }

            Connect2Proxy(or1);
        }
        public void SaveKSLEIST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryKSLEIST(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapKSLEIST(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertKSLEIST(dwLocal);
            }
            UpdateKSLEIST(dwLocal);

        }
        public void InsertKSLEIST(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "INSERT INTO KSLEIST ( KSLMANDANT,KSLAUFKRS,KSLAUFLFD,KSLAUFPOS,KSLAFOLGE,KSLAENDZL,KSLMDAT,KSLSCHICHT,KSLMZTV,KSLMZTB,KSLPERSNR,KSLMBENID,KSLMPROG,KSLMAFOLGE,KSLMCODE,KSLSA,KSLHERK,KSLVST,KSLIKOSTBW,KSLKAP,KSLDIV,KSLVERT,KSLMELDKZ,KSLERST,KSLAUFTYP,KSLAUFART,KSLTP,KSLFOLGEV,KSLFOLGEB,KSLSTKNR,KSLAGANG,KSLPLANKZ,KSLFIX,KSLMANUELKZ,KSLANTERLS,KSLERSTKZ,KSLZTAMMELD,KSLKUNDNR,KSLWERK,KSLABT,KSLWAKZ,KSLART,KSLVAR,KSLDESS,KSLCOLORIT,KSLBESCHICH,KSLFARBE,KSLZUSTAND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S:,:KSLLSKOST:,:KSLLIKOST:,:KSLLIKOSTI:,:KSLRSKOST:,:KSLRIKOST:,:KSLRIKOSTI:,:KSLRSKOSTF:,:KSLRIKOSTF:,:KSLRIKOSTIF:,:KSLSQKOSTM1:,:KSLSQKOSTM2:,:KSLSQKOSTM3:,:KSLSQKOSTM4:,:KSLSQKOSTM5:,:KSLIQKOSTM1:,:KSLIQKOSTM2:,:KSLIQKOSTM3:,:KSLIQKOSTM4:,:KSLIQKOSTM5:,:KSLIQKOSTIM1:,:KSLIQKOSTIM2:,:KSLIQKOSTIM3:,:KSLIQKOSTIM4:,:KSLIQKOSTIM5:,:KSLSQKOSTP1:,:KSLSQKOSTP2:,:KSLSQKOSTP3:,:KSLSQKOSTP4:,:KSLSQKOSTP5:,:KSLIQKOSTP1:,:KSLIQKOSTP2:,:KSLIQKOSTP3:,:KSLIQKOSTP4:,:KSLIQKOSTP5:,:KSLIQKOSTIP1:,:KSLIQKOSTIP2:,:KSLIQKOSTIP3:,:KSLIQKOSTIP4:,:KSLIQKOSTIP5:,:KSLGSKOST1:,:KSLGSKOST2:,:KSLGSKOST3:,:KSLGSKOST4:,:KSLGSKOST5:,:KSLGIKOST1:,:KSLGIKOST2:,:KSLGIKOST3:,:KSLGIKOST4:,:KSLGIKOST5:,:KSLGIKOSTI1:,:KSLGIKOSTI2:,:KSLGIKOSTI3:,:KSLGIKOSTI4:,:KSLGIKOSTI5:,:KSLAENDZLST:,:KSLAENDZLSV:,:KSLENDKZ:,:KSLABG:,:KSLARBPL:,:KSLLSTAR:,:KSLLO:,:KSLPAUFKRS:,:KSLPAUFLFD:,:KSLPAFOLGE:,:KSLFILLER:)"; or1.CommandText = InjectData(or1.CommandText, dwData);
                    or1.CommandText = InjectData(or1.CommandText, dwData);
                    break;
                case 2:
                    break;
            }


            Connect2Proxy(or1);
        }
        public DataSet QueryKSLEIST(DataRow dwData, int option = 1)
        {
            DataSet Return = new DataSet();
            DataTable tbLocal = null;
            DataSet Result = new DataSet();

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM KSLEIST WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM KSLEIST WHERE  "
                        + "  KSLMANDANT=:KSLMANDANT AND KSLAUFKRS=:KSLAUFKRS AND KSLAUFLFD=:KSLAUFLFD AND KSLAUFPOS=:KSLAUFPOS AND KSLAFOLGE=:KSLAFOLGE AND KSLAENDZL=:KSLAENDZL";
                    or1.Parameters.Add("KSLMANDANT", OracleType.NVarChar).Value = dwData["KSLMANDANT"].ToString();
                    or1.Parameters.Add("KSLAUFKRS", OracleType.NVarChar).Value = dwData["KSLAUFKRS"].ToString();
                    or1.Parameters.Add("KSLAUFLFD", OracleType.NVarChar).Value = dwData["KSLAUFLFD"].ToString();
                    or1.Parameters.Add("KSLAUFPOS", OracleType.NVarChar).Value = dwData["KSLAUFPOS"].ToString();
                    or1.Parameters.Add("KSLAFOLGE", OracleType.NVarChar).Value = dwData["KSLAFOLGE"].ToString();
                    or1.Parameters.Add("KSLAENDZL", OracleType.NVarChar).Value = dwData["KSLAENDZL"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT M.* FROM ABPOS JOIN KSLEIST M ON  KSLMANDANT=ABPMANDANT AND KSLAUFKRS=ABPAUFKRS AND KSLAUFLFD=ABPAUFLFD AND KSLAUFPOS=ABPAUFPOS WHERE  "
                        + "   KSLAUFKRS=:KSLAUFKRS AND KSLAUFLFD=:KSLAUFLFD  ";
                    or1.Parameters.Add("KSLAUFKRS", OracleType.NVarChar).Value = dwData["ABPAUFKRS"].ToString();
                    or1.Parameters.Add("KSLAUFLFD", OracleType.NVarChar).Value = dwData["ABPAUFLFD"].ToString();
                    break;
                case 3:
                    or1.CommandText = "SELECT KSLAUFKRS,KSLAUFLFD,KSLAUFPOS,KSLAFOLGE,KSLMGKG*0.001 AS KSLMGKG,KSLMDAT,KSLPERSNR,KSLSMNRKRS,KSLSMLFDNR,KSLSMPOS,NVL(AMBDEMA,'n') AS MACHINEID FROM KSLEIST LEFT JOIN AMSTAMM ON AMNRKRS=KSLSMNRKRS AND KSLSMLFDNR=AMLFDNR AND KSLSMPOS=AMPOS  WHERE  "
                        + "  KSLMANDANT=:KSLMANDANT AND KSLAUFKRS=:KSLAUFKRS AND KSLAUFLFD=:KSLAUFLFD AND KSLAUFPOS=:KSLAUFPOS ";
                    or1.Parameters.Add("KSLMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("KSLAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("KSLAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    or1.Parameters.Add("KSLAUFPOS", OracleType.NVarChar).Value = dwData["ABFAUFPOS"].ToString();
                    break;
                case 4:
                    or1.CommandText = "SELECT KSLAUFKRS,KSLAUFLFD,KSLAUFPOS,KSLAFOLGE,KSLMGKG*0.001 AS KSLMGKG,KSLMDAT,KSLPERSNR,KSLSMNRKRS,KSLSMLFDNR,KSLSMPOS,NVL(AMBDEMA,'n') AS MACHINEID FROM KSLEIST LEFT JOIN AMSTAMM ON AMNRKRS=KSLSMNRKRS AND KSLSMLFDNR=AMLFDNR AND KSLSMPOS=AMPOS  WHERE  "
                        + " JOIN ICC_QUERYTB ON KSLAUFKRS=ABPAUFKRS AND KSLAUFLFD =ABPAUFLFD AND KSLAUFPOS=ABPAUFPOS "
                         + " WHERE EXART=:EXART";
                    or1.Parameters.Add("KSLMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("KSLAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("KSLAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    or1.Parameters.Add("KSLAUFPOS", OracleType.NVarChar).Value = dwData["ABFAUFPOS"].ToString();
                    break;
                case 5:
                    or1.CommandText = "SELECT DISTINCT M.* FROM KSLEIST M"
                        + " JOIN ICC_QUERYTB X ON ABFAUFKRS=ABPAUFKRS AND ABFAUFLFD =ABPAUFLFD AND ABPAUFPOS=ABFAUFPOS "
                        + " WHERE  RTRIM(X.EXART)=:EXART";
                    or1.Parameters.Add("EXART", OracleType.NVarChar).Value = dwData["EXART"].ToString().Trim(); ;
                    break;
                default:
                    break;
            }

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "KSLEIST";
            }
            Return.Merge(Result);

            return Return;
        }
        public void UpdateKSLEIST(DataRow dwData, int option = 1)
        { 
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE KSLEIST SET KSLMANDANT=:KSLMANDANT:,KSLAUFKRS=:KSLAUFKRS:,KSLAUFLFD=:KSLAUFLFD:,KSLAUFPOS=:KSLAUFPOS:,KSLAFOLGE=:KSLAFOLGE:,KSLAENDZL=:KSLAENDZL:,KSLMDAT=:KSLMDAT:,KSLSCHICHT=:KSLSCHICHT:,KSLMZTV=:KSLMZTV:,KSLMZTB=:KSLMZTB:,KSLPERSNR=:KSLPERSNR:,KSLMBENID=:KSLMBENID:,KSLMPROG=:KSLMPROG:,KSLMAFOLGE=:KSLMAFOLGE:,KSLMCODE=:KSLMCODE:,KSLSA=:KSLSA:,KSLHERK=:KSLHERK:,KSLVST=:KSLVST:,KSLIKOSTBW=:KSLIKOSTBW:,KSLKAP=:KSLKAP:,KSLDIV=:KSLDIV:,KSLVERT=:KSLVERT:,KSLMELDKZ=:KSLMELDKZ:,KSLERST=:KSLERST:,KSLAUFTYP=:KSLAUFTYP:,KSLAUFART=:KSLAUFART:,KSLTP=:KSLTP:,KSLFOLGEV=:KSLFOLGEV:,KSLFOLGEB=:KSLFOLGEB:,KSLSTKNR=:KSLSTKNR:,KSLAGANG=:KSLAGANG:,KSLPLANKZ=:KSLPLANKZ:,KSLFIX=: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TIP3:,KSLIQKOSTIP4=:KSLIQKOSTIP4:,KSLIQKOSTIP5=:KSLIQKOSTIP5:,KSLGSKOST1=:KSLGSKOST1:,KSLGSKOST2=:KSLGSKOST2:,KSLGSKOST3=:KSLGSKOST3:,KSLGSKOST4=:KSLGSKOST4:,KSLGSKOST5=:KSLGSKOST5:,KSLGIKOST1=:KSLGIKOST1:,KSLGIKOST2=:KSLGIKOST2:,KSLGIKOST3=:KSLGIKOST3:,KSLGIKOST4=:KSLGIKOST4:,KSLGIKOST5=:KSLGIKOST5:,KSLGIKOSTI1=:KSLGIKOSTI1:,KSLGIKOSTI2=:KSLGIKOSTI2:,KSLGIKOSTI3=:KSLGIKOSTI3:,KSLGIKOSTI4=:KSLGIKOSTI4:,KSLGIKOSTI5=:KSLGIKOSTI5:,KSLAENDZLST=:KSLAENDZLST:,KSLAENDZLSV=:KSLAENDZLSV:,KSLENDKZ=:KSLENDKZ:,KSLABG=:KSLABG:,KSLARBPL=:KSLARBPL:,KSLLSTAR=:KSLLSTAR:,KSLLO=:KSLLO:,KSLPAUFKRS=:KSLPAUFKRS:,KSLPAUFLFD=:KSLPAUFLFD:,KSLPAFOLGE=:KSLPAFOLGE:,KSLFILLER=:KSLFILLER:"
                        + " WHERE  KSLMANDANT=:KSLMANDANT: AND KSLAUFKRS=:KSLAUFKRS: AND KSLAUFLFD=:KSLAUFLFD: AND KSLAUFPOS=:KSLAUFPOS: AND KSLAFOLGE=:KSLAFOLGE: AND KSLAENDZL=:KSLAENDZL:";
                    or1.CommandText = InjectData(or1.CommandText, dwData); 
                    break;
                case 2:
                    break;
            }

            Connect2Proxy(or1);
        }
    }
}
